unit Brparts;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  DBTables, DB, DBCtrls, StdCtrls, ExtCtrls, Grids, DBGrids, Buttons, patterns;

type
  TBrPartsForm = class(TForm)
    Panel1: TPanel;
    Navigator: TDBNavigator;
    ActivateBtn: TSpeedButton;
    EditBtn: TButton;
    Panel3: TPanel;
    CloseBtn: TButton;
    PartsGrid: TDBGrid;
    Bevel1: TBevel;
    procedure CloseBtnClick(Sender: TObject);
  private
//    function GetPartNo: Double;
//    procedure SetPartNo(NewPartNo: Double);
  public
//    property PartNo: Double read GetPartNo write SetPartNo;
    procedure setEventListener(AEventhandler: TNotifyEvent);
  end;

  TControllerParts = class(TController)
  private
    procedure onClick(Sender: TObject);
  protected
    procedure DoCommand(Command: string; args: string); override;
  public
    constructor Create;
  end;

var
  BrPartsForm: TBrPartsForm;

implementation

uses commandlist; //EdParts, DataMod;

{$R *.DFM}

//there two function not use anywhere

//function TBrPartsForm.GetPartNo: Double;
//begin
//  Result := TMastData.getInstance.PartsSource.Dataset.Fields[0].AsFloat;
//end;
//
//procedure TBrPartsForm.SetPartNo(NewPartNo: Double);
//begin
//  TMastData.getInstance.PartsSource.Dataset := TMastData.getInstance.Parts;
//  TMastData.getInstance.Parts.Locate('PartNo', NewPartNo, []);
//end;

procedure TBrPartsForm.CloseBtnClick(Sender: TObject);
begin
  Close;
end;

procedure TBrPartsForm.setEventListener(AEventhandler: TNotifyEvent);
begin
  EditBtn.OnClick := AEventHandler;
  ActivateBtn.OnClick := AEventHandler;
end;

//Controller

constructor TControllerParts.Create;
begin
  BrPartsForm := TBrPartsForm.Create(Application);
  BrPartsForm.setEventListener(onClick);
end;

procedure TControllerParts.onClick(Sender: TObject);
begin
  if (sender is TSpeedButton) and (TSpeedButton(sender).Caption = CMD_BACKORDERS) then
  begin
    if not BrPartsForm.ActivateBtn.Down then
      self.SendCommand(CMD_BACKORDERS, 'on')
    else
      self.SendCommand(CMD_BACKORDERS, 'off');
  end
  else if (sender is TButton) and (TButton(sender).Caption = CMD_EDIT_PARTS) then
  begin
    if BrPartsForm.ActivateBtn.Down then
      self.SendCommand(CMD_EDIT_PARTS, 'on')
    else
      self.SendCommand(CMD_EDIT_PARTS, 'off');
  end;
end;

procedure TControllerParts.DoCommand(Command: string; args: string);
begin
  if (command = CMD_BTN_PARTS) or (Command = CMD_SHOW_PARTS) then
    BrPartsForm.Show;
end;

initialization
  ControlCenter.RegController(TControllerParts.Create);



end.

